import java.util.regex.Matcher;
import java.util.regex.Pattern;

/*
 * 	This class represents the algorithm which extracts staff names from the html
 * 	of the tcd computing stafflist page.
 */
public class TCDStrategy implements Strategy {

    public TCDStrategy () {
    }

    public Faculty execute (StringBuffer buff) 
    {
    	Faculty ins = new Faculty();
    	//Pattern tcd = Pattern.compile("<a name=\"(\\w)*(\\')?(\\&(\\w)*\\;)?((,)?(\\s)?(\\w)*(\\&(\\w)*\\;)?)+",Pattern.CASE_INSENSITIVE);
    	Pattern tcd = Pattern.compile(">(\\w|-)+,((\\s|-)\\w+){1,3}</a>",Pattern.CASE_INSENSITIVE);
    	
    	//Pattern removeTags = Pattern.compile(">(\\w|-)+,((\\s|-)\\w+){1,3}</a>",Pattern.CASE_INSENSITIVE);
    	Pattern removeTags = Pattern.compile("<(\\/)?(\\w+)>",Pattern.CASE_INSENSITIVE);
		Matcher rough = tcd.matcher(buff);
		Matcher tags = removeTags.matcher(buff);

		/*
		 * while there are names left,
		 * remove the excess chars,
		 * save as a new person,
		 * add to institute
		 */
		while(rough.find())
		{
			String str = rough.group();
			tags = removeTags.matcher(str);
			str = tags.replaceAll("");
			Person p = new Person(str);
			ins.addStaffMember(p);
		}
		
        return ins;
    }
}

